﻿
@{
    ViewBag.Title = "edit";
    Layout = "~/Views/lib/_LayoutPageLib.cshtml";
}
<script src="~/lib/js/jquery.min.js"></script>
<form class="layui-form">
    <input type="hidden" value="@ViewBag.editName.Id" name="RolesId" class="layui-input" id="thisid" />
    @*当前用户id*@
   
    <div class="layui-form-item" style="margin-top:30px">
        <label for="L_pass" class="layui-form-label">
            当前员工姓名
        </label>
        <div class="layui-input-inline">
            <input disabled="disabled" class="layui-input" value="@ViewBag.editName.LoginName" >
        </div>        
    </div>
    
    <div class="layui-inline">        
        <label class="layui-form-label">选择新的身份</label>
        <div id="allroles" style="width:500px">
            @foreach (var item in ViewBag.userrolesyes)
            {
                <input type="checkbox" id="@item.Id" name="newid" title="@item.Name" checked="checked">

            }
            @foreach (var item in ViewBag.userrolesno)
            {
                <input type="checkbox" id="@item.Id" name="newid" title="@item.Name">

            }
            
        </div>
        
    </div>
    <div class="layui-form-item" style="margin-top:50px">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*" >
                <i class="layui-icon">&#x1005;</i> 确定修改
            </button>
        </div>
    </div>
    
</form>


<script>
    
    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;
        $ = layui.jquery;
        form.on('submit(*)', function (data) {   //点击修改执行方法
            var arr = [];
            var thisid = $("#thisid").val();
            
            for (var i = 0; i < $("#allroles").children().length ; i++) {
                if ($("#allroles").children()[i].checked == true) {
                    arr.push($("#allroles").children()[i].id);
                   
                }
            }
            if (arr.length <= 0) {
                layer.msg("至少选择一个权限", { icon: 2, time: 1500 });
                return false;
            }
            $.post("/adminList/edit", { Id: thisid, AllRoles: arr }, function (res) {
                if (res.success) {
                    layer.msg(res.msg, { icon: 1, time: 1500 }, function () {
                        window.location.reload()
                    });
                } else {
                    layer.msg(res.msg, { icon: 2, time: 1500 });
                }
            })
            return false;
        });

    });

</script>



